/**
 * 
 */
package com.emode.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.sql.rowset.serial.SerialArray;

import org.json.JSONArray;

import com.emode.base.BaseDaoImpl;
import com.emode.entity.SysPrivilege;
import com.emode.service.PrivilegeService;
import com.emode.util.StringUtils;

/**
 * @author emode
 *
 * 2014年12月26日 下午11:09:05

 */
public class PrivilegeServiceImpl extends BaseDaoImpl<SysPrivilege> implements PrivilegeService {

	public String childNodeData(SysPrivilege privilege, String ids) {
		List<SysPrivilege>  list = null;
		List<Object> tree = new ArrayList<Object>(); 
		System.out.println(ids);
		//当传值id不为空时， 通过id查找单个
		if(null!=ids){
			System.out.println(ids);
			list = findObjectByConditionWithNoPage(" and o.pid =?", new Object[]{ids});
		}else{
			list = findAll();
		}
		for(SysPrivilege privi:list){
			Integer parentid = 0;
			if(privi.getParentid()!=null){
				parentid = privi.getParentid().getPid();
			}
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("id", privi.getPid());
			map.put("pId", parentid);
			map.put("name", privi.getName());
			map.put("url", privi.getUrl());
			tree.add(map);
			
		}
		JSONArray obj = new JSONArray(tree);
		return obj.toString();
	}


}
